#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

#define MEMSIZE 1024

int main()
{
  int fd;
  pid_t pid;
  char *addr;
  addr = (char *)mmap(NULL, MEMSIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  if (addr == MAP_FAILED)
  {
    perror("mmap");
    exit(1);
  }

  pid = fork();
  if (pid < 0)
  {
    perror("fork");
    exit(1);
  } 
  if (pid == 0) // child
  {
    strcpy(addr, "Hello!");
    munmap(addr, MEMSIZE);
    exit(0);
  } 
  else // parent
  {
    wait(NULL);
    puts(addr);
    munmap(addr, MEMSIZE);
    exit(0);
  }
}
